﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DoAnWeb.DAO;
using DoAnWeb.DTO;
using DoAnWeb.BUS;

namespace DoAnWeb
{
    public partial class Register : System.Web.UI.Page
    {
        TaiKhoanDTO DTO = new TaiKhoanDTO();
        TaiKhoanBUS BUS = new TaiKhoanBUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (CurrentContext.IsLogged)
                    Response.Redirect("~/Default.aspx");

            }
        }

        protected void btnDangKy_Click(object sender, EventArgs e)
        {
            DTO.TenTaiKhoan = txtTenTaiKhoan.Text;
            DTO.MatKhau = txtMatKhauMoi.Text;
            DTO.HoTen = txtHoTen.Text;
            DTO.TenDoanhNghiep = "";
            DTO.MaLoaiTaiKhoan = "LTK2";

            DTO.NgaySinh = DateTime.Parse(txtNgaySinh.Text);
            DTO.DiaChi = txtDiaChi.Text;
            DTO.DienThoai = txtDienThoai.Text;
            DTO.Email = txtEmail.Text;
            if (rdNam.Checked)
            {
                DTO.GioiTinh = "Nam";
            }
            else
            {
                DTO.GioiTinh = "Nữ";
            }
            DTO.NgayDangKy = DateTime.Parse(DateTime.Now.ToShortDateString());
            bool KiemTra = BUS.Add(DTO);
            if (KiemTra)
            {
                Response.Redirect("~/RegisterSucceed.aspx?UserName=" + txtTenTaiKhoan.Text);
            }
            else
            {
                return;
            }
        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            string maXacNhan = txtMaXacNhan.Text;
            CaptchaControl1.ValidateCaptcha(maXacNhan);
            if (CaptchaControl1.UserValidated == false)
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }

    }
}